//
//  RootViewController.m
//  ShinnyHollywoodGalleryController
//
//  Created by Dario Lencina on 6/28/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import "RootViewController.h"
#import "ShinnyHollywoodGalleryController.h"

@implementation RootViewController


#pragma mark -
#pragma mark View lifecycle


- (void)viewDidLoad {
    [super viewDidLoad];
	self.title= @"demo ShinnyHollywoodGallery";
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}


/*
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}
*/
/*
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
	[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
	[super viewDidDisappear:animated];
}
*/

/*
 // Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	// Return YES for supported orientations.
	return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
 */


#pragma mark -
#pragma mark Table view data source

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
	// Configure the cell.
	cell.textLabel.text= @"shinnyHollywoodControllerWithDummyImages";
    return cell;
}

#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ShinnyHollywoodGalleryController * shinny= [[ShinnyHollywoodGalleryController alloc] init];
	[shinny setControllerImagesWithArray:[self fakeImagesArray]];
	[self.navigationController pushViewController:shinny animated:TRUE];
	[shinny release];
}

-(NSArray *)fakeImagesArray{
	NSString * neededPath= [NSString stringWithFormat:@"%@", [[NSBundle mainBundle] bundlePath]];
	NSArray * contentsOfMainBundle= [[NSFileManager defaultManager] contentsOfDirectoryAtPath:neededPath error:nil];
	NSMutableArray * mutableImageArray= [NSMutableArray new];
	for (NSString * nameOfFile in contentsOfMainBundle){
		if ([[nameOfFile substringFromIndex:[nameOfFile length]-3] isEqualToString:@"JPG"]) {
			[mutableImageArray addObject:[UIImage imageNamed:nameOfFile]];
		}
	}
	NSArray * inmutableCopyOfImageArray= [NSArray arrayWithArray:mutableImageArray];
	[mutableImageArray release];
	return inmutableCopyOfImageArray;
}
	
#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end

